package pl.droidsonroids.gif;

import com.getkeepsafe.relinker.ReLinker;

import ohos.app.Context;

/**
 * Helper used to work around native libraries loading on some systems.
 * See ReLinker for more details.
 */
public class LibraryLoader {
    private static final String BASE_LIBRARY_NAME = "pl_droidsonroids_gif";
    private static Context sAppContext;

    private LibraryLoader() {
    }

    /**
     * Initializes loader with given `Context`. Subsequent calls should have no effect since application Context is
     * retrieved.
     * Libraries will not be loaded immediately but only when needed.
     *
     * @param context any Context except null
     */
    public static void initialize(final Context context) {
        sAppContext = context;
    }

    static void loadLibrary() {
        try {
            System.loadLibrary(BASE_LIBRARY_NAME);
        } catch (final UnsatisfiedLinkError e) {
            ReLinker.loadLibrary(sAppContext, BASE_LIBRARY_NAME);
        }
    }
}
